#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int fd;
    int us;

    if(argc != 2) {
        printf("Usage:%s <dev>\n", argv[0]);
        return -1;
    }
    fd = open(argv[1], O_RDWR);
    if(fd == -1) {
        printf("can not open file %s\n", argv[1]);
        return -1;
    }
    while (1)
    {
        /* code */
        sleep(1);
        if(read(fd, &us, 4) == 4) {
            printf("dis:%d mm\n", us*340/2/1000);
        } else {
            printf("err\n");
        }
    }
    
    return 0;
}
